<!-- 房源列表 -->
<template>
    <view class="size-full">
        <z-paging
            ref="paging"
            v-model="list"
            @query="queryList"
            :fixed="false"
            :paging-style="{
                height: '100%',
            }"
            ><SourceCom
                v-for="(item, index) in list"
                :key="index"
                :value="item"
                @item-click="sellAction"
            ></SourceCom>
        </z-paging>
    </view>
</template>
<script setup lang="ts">
import SourceCom from "@/components/SourceCom/index.vue";
import { $global } from "@/store";
import type { listType } from "@/types";
import { ref } from "vue";
const list = ref<listType[]>([]);

const paging = ref();

const loadPage = (page: number) => {
    return new Promise((resolve) => {
        resolve([
            {
                title: "奥林清华1幢103" + page,
                desc: "4室2厅  |  170㎡",
                cost: "340万",
                average: "20000元/平",
                step: 0,
            },
            {
                title: "奥林清华1幢103" + page + 1,
                desc: "4室2厅  |  170㎡",
                cost: "340万",
                average: "20000元/平",
                step: 4,
            },
            {
                title: "奥林清华1幢103" + page,
                desc: "4室2厅  |  170㎡",
                cost: "340万",
                average: "20000元/平",
            },
            {
                title: "奥林清华1幢103" + page + 1,
                desc: "4室2厅  |  170㎡",
                cost: "340万",
                average: "20000元/平",
            },
            {
                title: "奥林清华1幢103" + page,
                desc: "4室2厅  |  170㎡",
                cost: "340万",
                average: "20000元/平",
            },
            {
                title: "奥林清华1幢103" + page + 1,
                desc: "4室2厅  |  170㎡",
                cost: "340万",
                average: "20000元/平",
            },
            {
                title: "奥林清华1幢103" + page,
                desc: "4室2厅  |  170㎡",
                cost: "340万",
                average: "20000元/平",
            },
            {
                title: "奥林清华1幢103" + page + 1,
                desc: "4室2厅  |  170㎡",
                cost: "340万",
                average: "20000元/平",
            },
            {
                title: "奥林清华1幢103" + page,
                desc: "4室2厅  |  170㎡",
                cost: "340万",
                average: "20000元/平",
            },
            {
                title: "奥林清华1幢103" + page + 1,
                desc: "4室2厅  |  170㎡",
                cost: "340万",
                average: "20000元/平",
            },
        ]);
    });
};
const queryList = (pageNo: number, pageSize: number) => {
    console.log("加载");
    if (list.value.length > 20) {
        paging.value.complete([]);
        return;
    }
    loadPage(pageNo)
        .then((res) => {
            paging.value.complete(res);
        })
        .catch((_) => {
            paging.value.complete(false);
        });
};

const sellAction = (action: "disSell" | "view" | "sign") => {
    if (action == "disSell") {
        $global.movePath("/pages/mine/children/SourcePage/index");
        return;
    }
    if (action == "view") {
        return;
    }
    if (action == "sign") {
        return;
    }
};
</script>
<style scoped lang="scss"></style>
